package o;

import android.util.SparseArray;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.a;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import o.and.c;
import o.and.e;

public final class age implements agc {
    private final agl ʻ = new agl(6, DnsConfig.MAX_CACHE_ENTRIES);
    private long ʼ;
    private aef ʽ;
    private final agt ˊ;
    private boolean ˊॱ;
    private final agl ˋ = new agl(7, DnsConfig.MAX_CACHE_ENTRIES);
    private d ˋॱ;
    private final agl ˎ = new agl(8, DnsConfig.MAX_CACHE_ENTRIES);
    private final boolean ˏ;
    private boolean ˏॱ;
    private final anc ͺ = new anc();
    private final boolean ॱ;
    private long ॱˊ;
    private String ॱॱ;
    private final boolean[] ᐝ = new boolean[3];

    static final class d {
        private long ʻ;
        private boolean ʻॱ;
        private byte[] ʼ = new byte[DnsConfig.MAX_CACHE_ENTRIES];
        private final anf ʽ = new anf(this.ʼ, 0, 0);
        private final aef ˊ;
        private boolean ˊॱ;
        private final SparseArray<c> ˋ = new SparseArray();
        private long ˋॱ;
        private final SparseArray<o.and.e> ˎ = new SparseArray();
        private final boolean ˏ;
        private boolean ˏॱ;
        private e ͺ = new e();
        private final boolean ॱ;
        private e ॱˊ = new e();
        private long ॱˎ;
        private int ॱॱ;
        private long ॱᐝ;
        private int ᐝ;

        static final class e {
            private boolean ʻ;
            private int ʼ;
            private boolean ʽ;
            private boolean ˊ;
            private int ˊॱ;
            private o.and.e ˋ;
            private int ˋॱ;
            private int ˎ;
            private boolean ˏ;
            private boolean ˏॱ;
            private int ͺ;
            private int ॱ;
            private int ॱˊ;
            private boolean ॱॱ;
            private int ᐝ;
            private int ᐝॱ;

            private e() {
            }

            public void ˏ() {
                this.ˊ = false;
                this.ˏ = false;
            }

            public void ˋ(int i) {
                this.ˎ = i;
                this.ˊ = true;
            }

            public void ˊ(o.and.e eVar, int i, int i2, int i3, int i4, boolean z, boolean z2, boolean z3, boolean z4, int i5, int i6, int i7, int i8, int i9) {
                this.ˋ = eVar;
                this.ॱ = i;
                this.ˎ = i2;
                this.ᐝ = i3;
                this.ʼ = i4;
                this.ʻ = z;
                this.ॱॱ = z2;
                this.ʽ = z3;
                this.ˏॱ = z4;
                this.ˋॱ = i5;
                this.ͺ = i6;
                this.ˊॱ = i7;
                this.ॱˊ = i8;
                this.ᐝॱ = i9;
                this.ˏ = true;
                this.ˊ = true;
            }

            public boolean ˎ() {
                return this.ˊ && (this.ˎ == 7 || this.ˎ == 2);
            }

            private boolean ˎ(e eVar) {
                if (this.ˏ) {
                    if (!eVar.ˏ || this.ᐝ != eVar.ᐝ || this.ʼ != eVar.ʼ || this.ʻ != eVar.ʻ) {
                        return true;
                    }
                    if (this.ॱॱ && eVar.ॱॱ && this.ʽ != eVar.ʽ) {
                        return true;
                    }
                    if (this.ॱ != eVar.ॱ && (this.ॱ == 0 || eVar.ॱ == 0)) {
                        return true;
                    }
                    if (this.ˋ.ˊॱ == 0 && eVar.ˋ.ˊॱ == 0 && (this.ͺ != eVar.ͺ || this.ˊॱ != eVar.ˊॱ)) {
                        return true;
                    }
                    if ((this.ˋ.ˊॱ == 1 && eVar.ˋ.ˊॱ == 1 && (this.ॱˊ != eVar.ॱˊ || this.ᐝॱ != eVar.ᐝॱ)) || this.ˏॱ != eVar.ˏॱ) {
                        return true;
                    }
                    if (this.ˏॱ && eVar.ˏॱ && this.ˋॱ != eVar.ˋॱ) {
                        return true;
                    }
                }
                return false;
            }
        }

        public d(aef o_aef, boolean z, boolean z2) {
            this.ˊ = o_aef;
            this.ॱ = z;
            this.ˏ = z2;
            ˊ();
        }

        public boolean ॱ() {
            return this.ˏ;
        }

        public void ॱ(o.and.e eVar) {
            this.ˎ.append(eVar.ˊ, eVar);
        }

        public void ˎ(c cVar) {
            this.ˋ.append(cVar.ˋ, cVar);
        }

        public void ˊ() {
            this.ˊॱ = false;
            this.ˏॱ = false;
            this.ॱˊ.ˏ();
        }

        public void ˏ(long j, int i, long j2) {
            this.ᐝ = i;
            this.ˋॱ = j2;
            this.ʻ = j;
            if (!(this.ॱ && this.ᐝ == 1)) {
                if (!this.ˏ) {
                    return;
                }
                if (!(this.ᐝ == 5 || this.ᐝ == 1 || this.ᐝ == 2)) {
                    return;
                }
            }
            e eVar = this.ͺ;
            this.ͺ = this.ॱˊ;
            this.ॱˊ = eVar;
            this.ॱˊ.ˏ();
            this.ॱॱ = 0;
            this.ˊॱ = true;
        }

        public void ॱ(byte[] bArr, int i, int i2) {
            if (this.ˊॱ) {
                int i3 = i2 - i;
                if (this.ʼ.length < this.ॱॱ + i3) {
                    this.ʼ = Arrays.copyOf(this.ʼ, (this.ॱॱ + i3) * 2);
                }
                System.arraycopy(bArr, i, this.ʼ, this.ॱॱ, i3);
                this.ॱॱ = i3 + this.ॱॱ;
                this.ʽ.ˊ(this.ʼ, 0, this.ॱॱ);
                if (this.ʽ.ˎ(8)) {
                    this.ʽ.ˊ();
                    int ˏ = this.ʽ.ˏ(2);
                    this.ʽ.ˋ(5);
                    if (this.ʽ.ˋ()) {
                        this.ʽ.ॱ();
                        if (this.ʽ.ˋ()) {
                            int ॱ = this.ʽ.ॱ();
                            if (!this.ˏ) {
                                this.ˊॱ = false;
                                this.ॱˊ.ˋ(ॱ);
                            } else if (this.ʽ.ˋ()) {
                                int ॱ2 = this.ʽ.ॱ();
                                if (this.ˋ.indexOfKey(ॱ2) < 0) {
                                    this.ˊॱ = false;
                                    return;
                                }
                                c cVar = (c) this.ˋ.get(ॱ2);
                                o.and.e eVar = (o.and.e) this.ˎ.get(cVar.ˎ);
                                if (eVar.ॱॱ) {
                                    if (this.ʽ.ˎ(2)) {
                                        this.ʽ.ˋ(2);
                                    } else {
                                        return;
                                    }
                                }
                                if (this.ʽ.ˎ(eVar.ᐝ)) {
                                    boolean z = false;
                                    boolean z2 = false;
                                    boolean z3 = false;
                                    int ˏ2 = this.ʽ.ˏ(eVar.ᐝ);
                                    if (!eVar.ʻ) {
                                        if (this.ʽ.ˎ(1)) {
                                            z = this.ʽ.ˎ();
                                            if (z) {
                                                if (this.ʽ.ˎ(1)) {
                                                    z3 = this.ʽ.ˎ();
                                                    z2 = true;
                                                } else {
                                                    return;
                                                }
                                            }
                                        }
                                        return;
                                    }
                                    boolean z4 = this.ᐝ == 5;
                                    int i4 = 0;
                                    if (z4) {
                                        if (this.ʽ.ˋ()) {
                                            i4 = this.ʽ.ॱ();
                                        } else {
                                            return;
                                        }
                                    }
                                    int i5 = 0;
                                    int i6 = 0;
                                    int i7 = 0;
                                    int i8 = 0;
                                    if (eVar.ˊॱ == 0) {
                                        if (this.ʽ.ˎ(eVar.ˏॱ)) {
                                            i5 = this.ʽ.ˏ(eVar.ˏॱ);
                                            if (cVar.ˊ && !z) {
                                                if (this.ʽ.ˋ()) {
                                                    i6 = this.ʽ.ˏ();
                                                } else {
                                                    return;
                                                }
                                            }
                                        }
                                        return;
                                    } else if (eVar.ˊॱ == 1 && !eVar.ॱˊ) {
                                        if (this.ʽ.ˋ()) {
                                            i7 = this.ʽ.ˏ();
                                            if (cVar.ˊ && !z) {
                                                if (this.ʽ.ˋ()) {
                                                    i8 = this.ʽ.ˏ();
                                                } else {
                                                    return;
                                                }
                                            }
                                        }
                                        return;
                                    }
                                    this.ॱˊ.ˊ(eVar, ˏ, ॱ, ˏ2, ॱ2, z, z2, z3, z4, i4, i5, i6, i7, i8);
                                    this.ˊॱ = false;
                                }
                            }
                        }
                    }
                }
            }
        }

        public boolean ˋ(long j, int i, boolean z, boolean z2) {
            int i2 = 0;
            if (this.ᐝ == 9 || (this.ˏ && this.ॱˊ.ˎ(this.ͺ))) {
                if (z && this.ˏॱ) {
                    ˋ(((int) (j - this.ʻ)) + i);
                }
                this.ॱᐝ = this.ʻ;
                this.ॱˎ = this.ˋॱ;
                this.ʻॱ = false;
                this.ˏॱ = true;
            }
            if (this.ॱ) {
                z2 = this.ॱˊ.ˎ();
            }
            boolean z3 = this.ʻॱ;
            if (this.ᐝ == 5 || (r10 && this.ᐝ == 1)) {
                i2 = 1;
            }
            this.ʻॱ = i2 | z3;
            return this.ʻॱ;
        }

        private void ˋ(int i) {
            this.ˊ.ˋ(this.ॱˎ, this.ʻॱ ? 1 : 0, (int) (this.ʻ - this.ॱᐝ), i, null);
        }
    }

    public age(agt o_agt, boolean z, boolean z2) {
        this.ˊ = o_agt;
        this.ॱ = z;
        this.ˏ = z2;
    }

    public void ˏ() {
        and.ˏ(this.ᐝ);
        this.ˋ.ˎ();
        this.ˎ.ˎ();
        this.ʻ.ˎ();
        this.ˋॱ.ˊ();
        this.ʼ = 0;
        this.ˊॱ = false;
    }

    public void ˏ(ady o_ady, a aVar) {
        aVar.ˊ();
        this.ॱॱ = aVar.ˎ();
        this.ʽ = o_ady.ˊ(aVar.ˏ(), 2);
        this.ˋॱ = new d(this.ʽ, this.ॱ, this.ˏ);
        this.ˊ.ˏ(o_ady, aVar);
    }

    public void ˋ(long j, int i) {
        this.ॱˊ = j;
        this.ˊॱ = ((i & 2) != 0 ? 1 : 0) | this.ˊॱ;
    }

    public void ˊ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        byte[] bArr = o_anc.ˏ;
        this.ʼ += (long) o_anc.ˊ();
        this.ʽ.ˎ(o_anc, o_anc.ˊ());
        while (true) {
            int ॱ2 = and.ॱ(bArr, ˋ, ॱ, this.ᐝ);
            if (ॱ2 == ॱ) {
                ॱ(bArr, ˋ, ॱ);
                return;
            }
            int ˊ = and.ˊ(bArr, ॱ2);
            int i = ॱ2 - ˋ;
            if (i > 0) {
                ॱ(bArr, ˋ, ॱ2);
            }
            int i2 = ॱ - ॱ2;
            long j = this.ʼ - ((long) i2);
            ˏ(j, i2, i < 0 ? -i : 0, this.ॱˊ);
            ˋ(j, ˊ, this.ॱˊ);
            ˋ = ॱ2 + 3;
        }
    }

    public void ˋ() {
    }

    private void ˋ(long j, int i, long j2) {
        if (!this.ˏॱ || this.ˋॱ.ॱ()) {
            this.ˋ.ˎ(i);
            this.ˎ.ˎ(i);
        }
        this.ʻ.ˎ(i);
        this.ˋॱ.ˏ(j, i, j2);
    }

    private void ॱ(byte[] bArr, int i, int i2) {
        if (!this.ˏॱ || this.ˋॱ.ॱ()) {
            this.ˋ.ˊ(bArr, i, i2);
            this.ˎ.ˊ(bArr, i, i2);
        }
        this.ʻ.ˊ(bArr, i, i2);
        this.ˋॱ.ॱ(bArr, i, i2);
    }

    private void ˏ(long j, int i, int i2, long j2) {
        if (!this.ˏॱ || this.ˋॱ.ॱ()) {
            this.ˋ.ॱ(i2);
            this.ˎ.ॱ(i2);
            if (this.ˏॱ) {
                if (this.ˋ.ॱ()) {
                    this.ˋॱ.ॱ(and.ˏ(this.ˋ.ॱ, 3, this.ˋ.ˊ));
                    this.ˋ.ˎ();
                } else if (this.ˎ.ॱ()) {
                    this.ˋॱ.ˎ(and.ˋ(this.ˎ.ॱ, 3, this.ˎ.ˊ));
                    this.ˎ.ˎ();
                }
            } else if (this.ˋ.ॱ() && this.ˎ.ॱ()) {
                List arrayList = new ArrayList();
                arrayList.add(Arrays.copyOf(this.ˋ.ॱ, this.ˋ.ˊ));
                arrayList.add(Arrays.copyOf(this.ˎ.ॱ, this.ˎ.ˊ));
                e ˏ = and.ˏ(this.ˋ.ॱ, 3, this.ˋ.ˊ);
                c ˋ = and.ˋ(this.ˎ.ॱ, 3, this.ˎ.ˊ);
                this.ʽ.ˎ(Format.ˏ(this.ॱॱ, "video/avc", amr.ˎ(ˏ.ˋ, ˏ.ˏ, ˏ.ॱ), -1, -1, ˏ.ˎ, ˏ.ʼ, SizeModifier.STABLE_STATE_SCALE, arrayList, -1, ˏ.ʽ, null));
                this.ˏॱ = true;
                this.ˋॱ.ॱ(ˏ);
                this.ˋॱ.ˎ(ˋ);
                this.ˋ.ˎ();
                this.ˎ.ˎ();
            }
        }
        if (this.ʻ.ॱ(i2)) {
            this.ͺ.ॱ(this.ʻ.ॱ, and.ˋ(this.ʻ.ॱ, this.ʻ.ˊ));
            this.ͺ.ˋ(4);
            this.ˊ.ˋ(j2, this.ͺ);
        }
        if (this.ˋॱ.ˋ(j, i, this.ˏॱ, this.ˊॱ)) {
            this.ˊॱ = false;
        }
    }
}
